<script setup>
import {ref,onMounted} from 'vue'

//检测是否有审批中的请假
const hasPendingLeave = ref(false)

onMounted(()=>{
  checkPendingLeave()
})

const checkPendingLeave = function (){
  const leaveRecords = uni.getStorageSync('leaveRecords') ||[]//获取本地的请假记录

  hasPendingLeave.value = leaveRecords.some(record =>record.status ==='pending')
}

// 跳转到请假表单页
const navigateToLeaveForm = () => {
  uni.navigateTo({
    url: '/pages/leaveForm/index'  // 对应pages.json中的表单页路径
  })
}
// 跳转到审批详情页
const navigateToApprovalDetail = () => {
  uni.navigateTo({
    url: '/pages/approvalDetail/index'
  })
}
</script>

<template>
  <view class="container">
    <!-- 主内容区 -->
    <!--  如果有审批中的请假-->
    <view v-if="hasPendingLeave" class="pending_container">
      <view class="pending_card" @click="navigateToApprovalDetail">
        <view class="card_header">
          <view class="header_icon">
            <image class="leave_icon" src="/static/image/leaveIcon.png"mode="aspectFit"></image>
            <text class="icon_text">请假申请</text>
          </view>

        </view>
        <text class="pending_message">还有一个请假在审批，你无法请假</text>
      </view>
    </view>
<!--    如果没有审批中的-->
    <view v-else class="content">
      <!-- 状态提示 -->
      <text class="status-text">当前暂无进行中的请假申请</text>

      <!-- 发起请假按钮 -->
      <view class="apply-btn" @click="navigateToLeaveForm">
        <text class="btn-text">发起请假</text>
      </view>

      <!-- 插图 -->
      <image
          class="illustration"
          src="/static/image/chaTu.png"
          mode="widthFix"
          alt="请假系统插图"
      ></image>
    </view>
  </view>
</template>

<style scoped>
.pending_container {
  padding: 40rpx 30rpx;
}

.pending_card {
  background-color: #fff;
  border-radius: 16rpx;
  padding: 30rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.card_header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
}

.header_icon {
  display: flex;
  align-items: center;
}

.leave_icon {
  width: 48rpx;
  height: 48rpx;
  margin-right: 16rpx;
}

.icon_text {
  font-size: 32rpx;
  font-weight: 500;
  color: #333;
}


.pending_message {
  font-size: 28rpx;
  color: #666;
  line-height: 40rpx;
}



.container {
  min-height: 100vh;
  background-color: #f5f5f5;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40rpx 20rpx;
  box-sizing: border-box;
}

.status-text {
  font-size: 28rpx;
  color: #666;
  margin-bottom: 60rpx;
}

.apply-btn {
  width: 100px;
  height: 34px;
  background: #9C131E;
  border-radius: 18px;
  position: relative;
}

.apply-btn:active {
  transform: scale(0.98);
  background-color: #244078;
}

.btn-text {
  width: 56px;
  height: 20px;
  font-weight: 400;
  font-size: 14px;
  color: #FFFFFF;
  letter-spacing: 0;
  position: absolute;
  left: 20px;
  top: 5px;
}

.illustration {
  width: 550rpx;
  height: auto;
  opacity: 0.95;
  margin-top: 40rpx;
}
</style>